package cn.wolfcode.luowowo.article.domain;


import cn.wolfcode.luowowo.common.domain.BaseDomain;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;

@Setter
@Getter
public class DestinationMonth extends BaseDomain{

    private String name;

    private String ref;

    private Long[] refIds;

    private int sequence;   //序号

    //添加编辑时，前端传入是long数组， 数据库保存的是id拼接的字符串
    public String getRef(){
        //id1,id2,id3
        return StringUtils.join(refIds, ",");
    }
    //从数据库拿出的id拼接字符串转换成数组
    public Long[] getRefIds(){
        Long[] ids = null;
        if(StringUtils.isNotBlank(ref)){
            String[] strs = ref.split(",");
            ids = new Long[strs.length];
            for (int i = 0; i <strs.length ; i++) {
                ids[i] =  Long.parseLong(strs[i]);
            }
        }
        return ids;
    }

}